def prost(n):
    for i in range(2,n+1):
     if n % i == 0 :
      return i 
    
def mega():
  dict_num = {
      "zero": 0,
      "one": 1,
      "two": 2,
      "three": 3,
      "four": 4,
      "five": 5,
      "six": 6,
      "seven": 7,
      "eight": 8,
      "nine": 9,
  }
  n = input()
  words = n.split()

  if words[0] == "zero":
    return "Wrong input"
  if len(words) != 3:
    return "Wrong input"
  for i in words: 
    if i not in dict_num:
      return "Wrong input"
      
  input_num = ""
  for i in words:
    input_num += str(dict_num[i])
    
  int_num = int(input_num)
  flag = True 
  l = 1
  r = 1
  while flag :
    x = int_num - l 
    if prost(x) == x :
      return x 
    else :
      l+=1
    y = int_num + r
    if prost(y) == y :
      return y 
    else :
      r+=1
    
mega()
